package com.xu.system.model.convert;

import com.xu.minio.model.MinioFile;
import com.xu.system.model.entity.SysFile;
import com.xu.system.model.pojo.file.FileVo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.util.List;

/**
 * 文件对象转化器
 *
 * @Author: 许乾伟
 * @Date: 2024/12/17 15:28
 */
@Mapper(componentModel = "spring")
public interface FileConvert {
    @Mappings({
            @Mapping(source = "id", target = "fileId"),
    })
    FileVo toFileVo(SysFile data);

    List<FileVo> toFileVoList(List<SysFile> list);
    @Mappings ({
            @Mapping(source = "fileId", target = "id"),
            @Mapping(target = "createBy", expression = "java(com.xu.security.utils.SecurityUtils.getUserId())"),
            @Mapping(target = "createTime", expression = "java(java.time.LocalDateTime.now())"),
            @Mapping(target = "updateBy", expression = "java(com.xu.security.utils.SecurityUtils.getUserId())"),
            @Mapping(target = "updateTime", expression = "java(java.time.LocalDateTime.now())")
    })
    SysFile toSysFile(MinioFile data);
}
